home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F18864_PremiershipTable.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-04-14  |  4.7 KB  |  115 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0"
  3.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4. <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
  5.  
  6. <xsl:key name="teams" match="result/home" use="@team"/>
  7. <xsl:key name="teams" match="result/away" use="@team"/>
  8. <xsl:key name="opposition" match="result/home" use="../away/@team"/>
  9. <xsl:key name="opposition" match="result/away" use="../home/@team"/>
  10. <xsl:key name="wins" match="result/away[@score > ../home/@score]" use="@team"/>
  11. <xsl:key name="wins" match="result/home[@score > ../away/@score]" use="@team"/>
  12. <xsl:key name="draws" match="result/away[@score = ../home/@score]" use="@team"/>
  13. <xsl:key name="draws" match="result/home[@score = ../away/@score]" use="@team"/>
  14.  
  15. <xsl:template match="/">
  16.     <html>
  17.         <head>
  18.             <title>
  19.                 <xsl:value-of select="/results/@nation"/>
  20.                 <xsl:text> </xsl:text>
  21.                 <xsl:value-of select="/results/@sponsor"/>
  22.                 <xsl:text> </xsl:text>
  23.                 <xsl:value-of select="/results/@league"/>
  24.                 <xsl:text> (condensed)</xsl:text>
  25.             </title>
  26.         </head>
  27.         <body>
  28.             <h3>
  29.                 <xsl:value-of select="/results/@nation"/>
  30.                 <xsl:text> </xsl:text>
  31.                 <xsl:value-of select="/results/@sponsor"/>
  32.                 <xsl:text> </xsl:text>
  33.                 <xsl:value-of select="/results/@league"/>
  34.                 <xsl:text> (condensed)</xsl:text>
  35.             </h3>
  36.             <table border="0" bgcolor="Black" cellspacing="1" style="font-family: Courier New, Courier, monospace; font-size: 12;">
  37.                 <tr bgcolor="Silver">
  38.                     <th>Pos</th>
  39.                     <th>Team</th>
  40.                     <th>Pld</th>
  41.                     <th width="20">W</th>
  42.                     <th width="20">D</th>
  43.                     <th width="20">L</th>
  44.                     <th width="20">F</th>
  45.                     <th width="20">A</th>
  46.                     <th width="20">GD</th>
  47.                     <th width="20">Pts</th>
  48.                 </tr>
  49.                 <!-- apply template to each distinct team -->
  50.                 <xsl:apply-templates select="(/results/result/home|/results/result/away)[generate-id(.) = generate-id(key('teams',@team))]">
  51.                     <!-- sort primarily on points -->
  52.                     <xsl:sort select="(count(key('wins',@team)) * 3) + (count(key('draws',@team)))" data-type="number" order="descending"/>
  53.                     <!-- secondary sort by goal difference -->
  54.                     <xsl:sort select="sum(key('teams',@team)/@score) - sum(key('opposition',@team)/@score)" data-type="number" order="descending"/>
  55.                     <!-- final sort on goals scored -->
  56.                     <xsl:sort select="sum(key('teams',@team)/@score)" data-type="number" order="descending"/>
  57.                 </xsl:apply-templates>
  58.             </table>
  59.             <sub>
  60.                 <xsl:text>(Results up to and including </xsl:text>
  61.                 <!-- find max date - don't rely on results being sorted -->
  62.                 <xsl:variable name="last-date">
  63.                     <xsl:apply-templates select="/results/result/@date[1]" mode="find-max">
  64.                         <xsl:sort select="translate(.,'-','')" data-type="number" order="ascending"/>
  65.                     </xsl:apply-templates>
  66.                 </xsl:variable>
  67.                 <xsl:value-of select="concat(substring($last-date,9,2),'/',substring($last-date,6,2),'/',substring($last-date,1,4))"/>
  68.                 <xsl:text>)</xsl:text>
  69.             </sub>
  70.         </body>
  71.     </html>
  72. </xsl:template>
  73.  
  74. <xsl:template match="home|away">
  75.     <!-- store any nodesets used more than once -->
  76.     <xsl:variable name="games" select="key('teams',@team)"/>
  77.     <!-- calculate anything that is used more than once -->
  78.     <!-- saves processing keys excessively -->
  79.     <xsl:variable name="played" select="count($games)"/>
  80.     <xsl:variable name="wins" select="count(key('wins',@team))"/>
  81.     <xsl:variable name="draws" select="count(key('draws',@team))"/>
  82.     <xsl:variable name="goals-for" select="sum($games/@score)"/>
  83.     <xsl:variable name="goals-against" select="sum(key('opposition',@team)/@score)"/>
  84.     <!-- now display the table row -->
  85.     <tr bgcolor="#{substring('FFFFFF8AF7D6',((position() mod 2)*6)+1,6)}">
  86.         <!-- league position -->
  87.         <td align="right"><xsl:value-of select="position()"/></td>
  88.         <!-- team name -->
  89.         <td><xsl:value-of select="@team"/></td>
  90.         <!-- games played -->
  91.         <td align="right"><xsl:value-of select="$played"/></td>
  92.         <!-- wins -->
  93.         <td align="right"><xsl:value-of select="$wins"/></td>
  94.         <!-- draws -->
  95.         <td align="right"><xsl:value-of select="$draws"/></td>
  96.         <!-- losses -->
  97.         <td align="right"><xsl:value-of select="$played - $wins - $draws"/></td>
  98.         <!-- goals for -->
  99.         <td align="right"><xsl:value-of select="$goals-for"/></td>
  100.         <!-- goals against -->
  101.         <td align="right"><xsl:value-of select="$goals-against"/></td>
  102.         <!-- goal difference -->
  103.         <td align="right"><xsl:value-of select="$goals-for - $goals-against"/></td>
  104.         <!-- points -->
  105.         <td align="right"><xsl:value-of select="($wins * 3) + $draws"/></td>
  106.     </tr>
  107. </xsl:template>
  108.  
  109. <xsl:template match="@date" mode="find-max">
  110.     <xsl:if test="position() = last()">
  111.         <xsl:value-of select="."/>
  112.     </xsl:if>
  113. </xsl:template>
  114.  
  115. </xsl:stylesheet>